package com.nineclock.approve.controller;

import com.nineclock.api.approve.ApproveDefinitionControllerApi;
import com.nineclock.approve.dto.ApproveDefinitionResultDto;
import com.nineclock.approve.dto.ApproveDefinitionSaveDto;
import com.nineclock.approve.dto.ApproveGroupDefinitionDto;
import com.nineclock.approve.service.ApproveDefinitionService;
import com.nineclock.common.entity.Result;
import com.nineclock.common.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/approve")
public class ApproveDefinitionController implements ApproveDefinitionControllerApi {
    @Autowired
    ApproveDefinitionService approveDefinitionService;
    /**
     * 流程定义: 获取序列
     *
     * @return
     */
    @GetMapping("/seq")
    @Override
    public Result<String> seq() {
        // 生成UUID,用于每一个表单组件标识
        return Result.success(UUIDUtils.getUUID());
    }

    /**
     * 查询审批列表
     * @return
     */
    @GetMapping("/approveGroupDefinition")
    @Override
    public Result<List<ApproveGroupDefinitionDto>> queryDefinitionGroup() {
        List<ApproveGroupDefinitionDto> list = approveDefinitionService.queryDefinitionGroup();
        return Result.success(list);
    }

    /**
     * 新增/修改
     * @param approveDefinitionSaveDto
     * @return
     */
    @PostMapping("/approveDefinition")
    @Override
    public Result saveApproveDefinition(@RequestBody ApproveDefinitionSaveDto approveDefinitionSaveDto) {
        approveDefinitionService.saveApproveDefinition(approveDefinitionSaveDto);
        return Result.success();
    }

    /**
     * 根据ID查询数据并进行回显
     * @param id
     * @return
     */
    @GetMapping("/approveDefinition/{id}")
    @Override
    public Result<ApproveDefinitionResultDto> queryDefinitionById(@PathVariable("id") String id) {
        ApproveDefinitionResultDto resultDto = approveDefinitionService.queryDefinitionById(id);
        return Result.success(resultDto);
    }
}
